package com.fzu.ess.ess.controller;
/**
 * Created by ercha on 2016/1/8.
 */

import com.fzu.ess.common.Model.JsonModel;
import com.fzu.ess.sys.entity.User;
import com.fzu.ess.sys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * @author ercha
 * @ClassName: AdminController
 * @Description:
 * @Date 2016/01/08 19:32
 * @History:// 历史修改记录
 * <author>  // 修改人1
 * <time>    // 修改时间
 * <desc>    // 描述修改内容
 */
@Controller
@RequestMapping(value = "/admin")
public class AdminController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/create", method = RequestMethod.GET)
    public String createPage(){
        return "/jsp/admin/admin/adminCreate.jsp";
    }

    @ResponseBody
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public JsonModel create(User admin){
        return userService.createAdmin(admin);
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String listPage(){
        return "/jsp/admin/admin/adminList.jsp";
    }

    @ResponseBody
    @RequestMapping(value = "/pageData", method = RequestMethod.GET)
    public JsonModel pageData(@RequestParam(value = "page") Integer pageNumber, @RequestParam Integer pageSize,
                              @RequestParam(required = false) String filter){
        System.out.println("here!!!!!");
        return userService.adminPageData(pageNumber, pageSize, filter);
    }

    @ResponseBody
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public JsonModel delete(String id){
        return userService.deleteAdmin(id);
    }

    @RequestMapping(value = "/resetPassword", method = RequestMethod.GET)
    public String resetPasswordPage(@RequestParam(value = "id") String id, Model model) {
        model.addAttribute("id", id);
        return "/jsp/admin/admin/resetPassword.jsp";
    }

    @ResponseBody
    @RequestMapping(value = "/resetPassword", method = RequestMethod.POST)
    public JsonModel resetPassword(String id, String password){
        return userService.resetAdminPassword(id, password);
    }
}
